using System;
using System.Collections.Generic;
using System.Text;
using LibrErian.Common;
using LibrErian.Model;
using Microsoft.Practices.CompositeUI.SmartParts;
using LibrErian.Common.Constants;
using Microsoft.Practices.CompositeUI.WinForms;

namespace LibrErian.Modules.BasicBook
{
    public class EditBookController : WorkItemController
    {
        public void Run(Book bookToEdit)
        {
            WorkItem.State["Book"] = bookToEdit;

            // Construct a key to register the work item in ourselves
            string key = string.Format("Book#{0}", bookToEdit.Id);

            BookView bookView = WorkItem.SmartParts[key] as BookView;
            if (bookView == null)
            {
                bookView = WorkItem.SmartParts.AddNew<BookView>(key);
            }

            ISmartPartInfo info = new SmartPartInfo();
            info.Title = string.Format("Edit book - {0}", bookToEdit.Title);

            WorkItem.Workspaces[WorkspaceNames.WindowWorkspace].Show(bookView, info);
        }
    }
}
